# Neo4j Knowledge Graph Tutorial - Docker Compose
# ================================================
# 
# Usage:
#   docker-compose up -d        # Start Neo4j
#   docker-compose down         # Stop Neo4j
#   docker-compose logs -f      # View logs
#
# Access:
#   Browser: http://localhost:7474
#   Bolt: bolt://localhost:7687
#   Default credentials: neo4j/password123

version: '3.8'

services:
  neo4j:
    image: neo4j:5.15.0-enterprise
    container_name: neo4j-tutorial
    hostname: neo4j
    ports:
      - "7474:7474"  # HTTP Browser
      - "7687:7687"  # Bolt Protocol
      - "7473:7473"  # HTTPS (optional)
    environment:
      # Authentication
      - NEO4J_AUTH=neo4j/password123
      
      # License
      - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes
      
      # Plugins (GDS and APOC)
      - NEO4J_PLUGINS=["graph-data-science", "apoc"]
      
      # Memory Configuration
      - NEO4J_dbms_memory_pagecache_size=2G
      - NEO4J_dbms_memory_heap_initial__size=1G
      - NEO4J_dbms_memory_heap_max__size=2G
      
      # Security - Allow GDS and APOC procedures
      - NEO4J_dbms_security_procedures_unrestricted=gds.*,apoc.*
      - NEO4J_dbms_security_procedures_allowlist=gds.*,apoc.*
      
      # APOC Configuration
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
      
      # Vector Index Support
      - NEO4J_dbms_security_allow__csv__import__from__file__urls=true
      
      # Logging
      - NEO4J_dbms_logs_query_enabled=INFO
      - NEO4J_dbms_logs_query_threshold=0s
      
    volumes:
      # Persistent data
      - neo4j_data:/data
      - neo4j_logs:/logs
      - neo4j_plugins:/plugins
      - neo4j_import:/var/lib/neo4j/import
      
      # Mount local data directory for imports (remove :ro to avoid chown issues)
      - ./data:/var/lib/neo4j/import/data
      
    healthcheck:
      test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:7474 || exit 1"]
      interval: 15s
      timeout: 10s
      retries: 5
      start_period: 30s
    
    restart: unless-stopped
    
    networks:
      - neo4j-network

  # Optional: Neo4j Bloom for visualization
  # Uncomment if you have a Bloom license
  # bloom:
  #   image: neo4j/bloom:2.8.0
  #   container_name: neo4j-bloom
  #   ports:
  #     - "8085:8085"
  #   environment:
  #     - NEO4J_URI=bolt://neo4j:7687
  #   depends_on:
  #     - neo4j
  #   networks:
  #     - neo4j-network

networks:
  neo4j-network:
    driver: bridge

volumes:
  neo4j_data:
    name: neo4j-tutorial-data
  neo4j_logs:
    name: neo4j-tutorial-logs
  neo4j_plugins:
    name: neo4j-tutorial-plugins
  neo4j_import:
    name: neo4j-tutorial-import
